package com.smile.service.impl;

import cn.dev33.satoken.spring.context.path.ApplicationContextPathLoading;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smile.commons.page.MyBatisPlusPageConverter;
import com.smile.mapper.*;
import com.smile.model.domain.*;
import com.smile.model.dto.request.AddMediaShareRequestDTO;
import com.smile.model.dto.request.GetMediaDeviceRequestDTO;
import com.smile.model.dto.request.GetMediaRequestDTO;
import com.smile.model.dto.request.GetMqttConfigRequestDTO;
import com.smile.model.response.response.*;
import com.smile.service.ConfigService;
import com.smile.service.MediaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
public class ConfigServiceImpl implements ConfigService {

    @Autowired
    private OrganizationMapper organizationMapper;
    @Value("${spring.mqtt.server-url}")
    private String brokerUrl;

    @Value("${spring.mqtt.username}")
    private String username;

    @Value("${spring.mqtt.password}")
    private String password;



    @Override
    public GetMqttConfigResponseDTO getMqttConfig(GetMqttConfigRequestDTO getMqttConfigRequestDTO){
        GetMqttConfigResponseDTO getMqttConfigResponseDTO = new GetMqttConfigResponseDTO();
        SmilePlusOrganization smilePlusOrganization = organizationMapper.selectById(getMqttConfigRequestDTO.getOrgId());
        if(ObjectUtil.isNotEmpty(smilePlusOrganization)){
            getMqttConfigResponseDTO.setOrganizationCode(smilePlusOrganization.getOrganizationCode());
            getMqttConfigResponseDTO.setDeviceBindingCode(smilePlusOrganization.getDeviceBindingCode());
        }
        getMqttConfigResponseDTO.setAddress(brokerUrl);
        getMqttConfigResponseDTO.setUsername(username);
        getMqttConfigResponseDTO.setPassword(password);
        return getMqttConfigResponseDTO;
    }

}
